import { WSController, OnWSMessage, OnWSConnection, Inject, App } from '@midwayjs/core';
import { Context, Application } from '@midwayjs/socketio';

@WSController('/')
export class HelloSocketController {

    @Inject()
    ctx: Context;

    @App()
    app: Application;

    @OnWSConnection()
    async onConnectionMethod() {
        console.log('on client connect', this.ctx.id);
    }

    @OnWSMessage('myEvent')
    async gotMessage(data) {
        console.log('on data got', this.ctx.id, data);
    }

    @OnWSMessage('send')
    async gotMessage2(val) {
        console.log("回应数据1111111111", val);
        // this.ctx.emit("minde", val)
        console.log(this.app);
        this.ctx.local.emit("mingde",val );
        this.ctx.emit("mingde", { code:200,...val});
    }







}